package com.agile.leetcode.kmp.kmpforce;

/**
 * @Author ChenZhangKun
 * @Date 2020/9/1 16:53
 */
public class KmpForce {
    public static void main(String[] args) {
        // 定义字符串
        String str1="abacnsjksndsj";
        String str2="ks";
        System.out.println(get(str1, str2));
    }

    /**
     * 暴力匹配
     * @param str1 匹配的字符串
     * @param str2 被匹配的字符串
     * @return
     */
    public static Integer get(String str1,String str2){
        char[] chars = str1.toCharArray();
        char[] chars1 = str2.toCharArray();
        int i=0,j=0;
        while (j<chars1.length&&i<chars.length){
            if (chars[i]==chars1[j]){
                i++;
                j++;
            }
            if (j==chars1.length-1){
                return i-j;
            }
            if (chars[i]!=chars1[j]){
                i=i-j+1;
                j=0;
            }
        }
        return -1;
    }
}
